import Vue from 'vue'
import store from './store'
import App from './App'

import uView from "uview-ui";
Vue.use(uView);

import moment from "moment"

var util = require('./common/util.js')

// import Json from './Json' //测试用数据
// import * as otherApi from './config/api.js'

import * as request from '@/service.js'
import dateFormat from '@/dateFormat.js'

import { cloudUrl, cloudStorageUrl } from '@/env.js'
Vue.prototype.$cloudUrl = cloudUrl
Vue.prototype.$cloudStorageUrl = cloudStorageUrl
Vue.prototype.$getCloudStorageUrl = path => {
	return cloudStorageUrl + '/static/img' + path || ''
}

Vue.prototype.$getImgUrl = (fileID) => {
	return `${cloudUrl}/getTecentImgUrl?fileID=${fileID}`
}

Vue.prototype.$showError = (msg) => {
	uni.showToast({
		title: msg || '未知错误',
		icon: "none",
		duration: 1500
	})
}

Vue.prototype.$copy = (text, callback = null, tips = '已复制') => {
	// #ifdef H5
	util.copyContentH5({
		text,
		success: () => {
			if (tips) {
				uni.showToast({
					title: tips,
					icon: "none"
				})
			}
			if (callback) {
				callback()
			}
		}
	})
	// #endif
	// #ifndef H5
	uni.setClipboardData({
		data: text,
		success: () => {
			if (tips) {
				uni.showToast({
					title: tips,
					icon: "none"
				})
			}
			if (callback) {
				callback()
			}
		},
		showToast: false,
		fail: (err) => {
			console.error(err)
		}
	})
	// #endif
}

Vue.prototype.$toast = (msg, icon = 'none') => {
	return new Promise((resolve, reject) => {
		uni.showToast({
			title: msg || '-',
			icon: icon
		})
		setTimeout(() => {
			resolve()
		}, 1500)
	})
}

Vue.config.productionTip = false
Vue.prototype.$fire = new Vue();
Vue.prototype.$store = store;
// Vue.prototype.$api = {msg, json, prePage};

Vue.prototype.$http = request
Vue.prototype.$dateUtil = util.dateUtils
Vue.prototype.$formatTime = (time, pattern = 'YYYY-MM-DD hh:mm:ss') => {
	return moment(time).format(pattern)
}
Vue.prototype.$moment = moment

Vue.prototype.$log = (tag, msg)=>{
	if (getApp().globalData.showLog) {
		// console.log(`${new Date().format('yyyy-MM-dd hh:mm:ss')} DEBUG ` + tag, msg)
	}
}

import dbHelper from "./common/db-helper.js"
Vue.prototype.$dbHelper = dbHelper

App.mpType = 'app'

const app = new Vue({
    ...App
})
app.$mount()
